﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xunit;
using YAPL.Language.Core;
using YAPL.Language.Core.Types;

namespace YAPL.Test.YAPL.Language.Core.Lib.GlobalFunctions {
	public class TypeNameTest {

		private readonly YAPLFunction _typeName;

		public TypeNameTest() {
			_typeName = GCL.Get(ClassNames.GlobalScope).Methods[FunctionNames.TypeName];
		}

		[Fact]
		public void FunctionShouldReturnCorrectTypeNameForYaplTypes() {
			YAPLString result = null;
			var scope = new Scope();
			scope["unnamed0"] = new YAPLString("123");
			Assert.DoesNotThrow(() => result = (YAPLString)_typeName.Call(scope));
			Assert.NotNull(result);
			Assert.Equal("YAPLString", result.StrValue);

			scope["unnamed0"] = new YAPLInt(12);
			Assert.DoesNotThrow(() => result = (YAPLString)_typeName.Call(scope));
			Assert.NotNull(result);
			Assert.Equal("YAPLInt", result.StrValue);
		}

		[Fact]
		public void FunctionShouldReturnCorrectTypeNameForUndefinedObject() {
			YAPLString result = null;
			var scope = new Scope();
			scope["unnamed0"] = YAPLObject.UNDEFINED;
			Assert.DoesNotThrow(() => result = (YAPLString)_typeName.Call(scope));
			Assert.NotNull(result);
			Assert.Equal("undefined", result.StrValue);
		}
	}
}
